﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace System.Windows
{
    internal class PointHelper
    {
        Point _value;
        public Point Value
        {
            get { return _value; }
            set { _value = value; }
        }

        public PointHelper(Point Input)
        {
            _value = Input;
        }

        public PointHelper()
        {
        }

        /// <summary>
        /// 两个点相减得到一个向量
        /// </summary>
        /// <param name="point1"></param>
        /// <param name="point2"></param>
        /// <returns>两点的向量</returns>
        public static Vector operator -(PointHelper point1, PointHelper point2)
        {
            return new Vector(point1._value.X - point2._value.X, point1._value.Y - point2._value.Y);
        }

        /// <summary>
        /// 两个点相加得到一个全新的点
        /// </summary>
        /// <param name="point"></param>
        /// <param name="vector"></param>
        /// <returns></returns>
        public static PointHelper operator +(PointHelper point, Vector vector)
        {
            PointHelper result = new PointHelper();

            result._value.X = vector.X + point.Value.X;
            result._value.Y = vector.Y + point.Value.Y;

            return result;
        }
    }






    /// <summary>
    /// 向量
    /// </summary>
    internal struct Vector
    {
        Point _point;

        public Vector(double x, double y)
        {
            _point = new Point(x, y);
        }

        /// <summary>
        /// 向量长度
        /// </summary>
        public double Length
        {
            get { return (Math.Sqrt(Math.Pow(_point.X, 2.0) + Math.Pow(_point.Y, 2.0))); }
        }

        /// <summary>
        /// 向量归一化处理（无法对长度为1的向量做归一化处理）
        /// </summary>
        public void Normalize()
        {
            if (Length == 0)
                throw new System.InvalidOperationException("Vector Length is zero, can not normalize");

            double l = Length;
            _point.X /= l;
            _point.Y /= l;
        }

        public double X
        {
            get { return _point.X; }
            set { _point.X = value; }
        }

        public double Y
        {
            get { return _point.Y; }
            set { _point.Y = value; }
        }


        public static Vector operator -(Vector vector1, Vector vector2)
        {
            return new Vector(vector1.X - vector2.X, vector1.Y - vector2.Y);
        }


        public static Vector operator -(Vector vector)
        {
            return new Vector(-vector.X, -vector.Y);
        }


        public static Vector operator *(double scalar, Vector vector)
        {
            return new Vector(vector.X * scalar, vector.Y * scalar);
        }

        public static Vector operator *(Vector vector, double scalar)
        {
            return new Vector(vector.X * scalar, vector.Y * scalar);
        }

        public static double operator *(Vector vector1, Vector vector2)
        {
            return (vector1.X * vector2.X) + (vector1.Y * vector2.Y);
        }

        public static Vector operator +(Vector vector1, Vector vector2)
        {
            return (new Vector(vector2.X + vector1.X, vector2.Y + vector1.Y));
        }


        public static Point operator +(Point point, Vector vector)
        {
            return new Point(point.X + vector.X, point.Y + vector.Y);
        }

    }
}
